#include "common.hpp"
#include <errno.h>
#include <sys/wait.h>

int
main(int argc, char* argv[])
{
	if ( argc < 2 )
	{
		cerr << "stelnet [PORT]" << endl;
		return EXIT_FAILURE;
	}

	PWIOPoll* pPoll(PWIOPoll::create("epoll"));
	if ( !pPoll )
	{
		return EXIT_FAILURE;
	}

	if ( !pPoll->initialize(NULL) )
	{
		return EXIT_FAILURE;
	}

	XListener lsnr;
	if ( !lsnr.openServer(pPoll, "0.0.0.0", argv[1]) )
	{
		return EXIT_FAILURE;
	}

	int res;
	pid_t cpid;
	while ( pPoll->dispatch(1000) )
	{
		if ( (cpid = waitpid(-1, &res, WNOHANG)) > 0 )
		{
			cerr << "child pid: " << cpid << " result: " << res << endl;
		}
	}
}

